//
//  JQMineSetVC.m
//  JQLive
//
//  Created by Bruce on 2020/8/18.
//  Copyright © 2020 mlkq. All rights reserved.
//

#import "JQMineSetVC.h"
#import "UIView+Extension.h"
#import "JQMineSetLogoutCell.h"
#import "JQMineProfileCell.h"
#import "JQMineSetSafeManageVC.h"
#import "MYSimpleWebVC.h"// webVC 跳转

@interface JQMineSetVC ()<UITableViewDelegate, UITableViewDataSource, UITextFieldDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, copy) NSArray *nameArr;

@end

@implementation JQMineSetVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"更多设置";
    self.nameArr = @[@"安全管理", @"检测更新", @"隐私协议"];
    
    [self addTopView];
    [self addNavBar];
    [self addTableView];
}
- (void)addNavBar{
    MY_WEAK;
    UILabel *titleLb = [[UILabel alloc] init];
    [self.view addSubview:titleLb];
    [titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        MY_STRONG;
        make.size.mas_equalTo(CGSizeMake(145, 25));
        make.centerX.mas_equalTo(strongSelf.view);
        make.top.mas_equalTo(strongSelf.view.mas_top).offset(44);
    }];
    titleLb.textColor = [UIColor whiteColor];
    titleLb.font = [UIFont systemFontOfSize:18];
    titleLb.text = self.title;
    titleLb.textAlignment = NSTextAlignmentCenter;
    
    
    // 返回
    UIButton *backBtn = [[UIButton alloc] init];
    [backBtn setImage:[UIImage svgImageNamed:@"nav_back" size:CGSizeMake(15, 15)] forState:UIControlStateNormal];
    [self.view addSubview:backBtn];
    [backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        MY_STRONG;
        make.left.mas_equalTo(strongSelf.view.mas_left).offset(18);
        make.centerY.mas_equalTo(titleLb);
        make.size.mas_equalTo(CGSizeMake(22, 22));
    }];
    [backBtn addTapBlock:^(UIButton * _Nonnull btn) {
        [self.navigationController popViewControllerAnimated:YES];
    }];
    
}
- (void)addTopView{
    UIView *topView = [[UIView alloc] init];
    [self.view addSubview:topView];
    topView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 109);


    // gradient
    CAGradientLayer *gl = [CAGradientLayer layer];
    gl.frame = CGRectMake(0,0,SCREEN_WIDTH,109);
    gl.startPoint = CGPointMake(1, 0.5);
    gl.endPoint = CGPointMake(0, 0.51);
    gl.colors = @[(__bridge id)[UIColor colorWithRed:17/255.0 green:0/255.0 blue:169/255.0 alpha:1.0].CGColor, (__bridge id)[UIColor colorWithRed:9/255.0 green:37/255.0 blue:215/255.0 alpha:1.0].CGColor];
    gl.locations = @[@(0), @(1.0f)];
    [topView.layer addSublayer:gl];
    
//    [self.navigationController.navigationBar.layer addSublayer:gl];

}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = YES;
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    self.navigationController.navigationBar.hidden = NO;
}

// tabview 加载
- (void)addTableView{
    UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 87, SCREEN_WIDTH, SCREEN_HEIGHT-87) style:UITableViewStyleGrouped];
    [self.view addSubview:tableView];
    self.tableView = tableView;
    tableView.backgroundColor = kColorWithHex(0xF2F4FC);
    [tableView round:20 RectCorners:UIRectCornerTopLeft|UIRectCornerTopRight];
    tableView.delegate = self;
    tableView.dataSource = self;
    [tableView registerClass:[JQMineProfileCell class] forCellReuseIdentifier:NSStringFromClass([JQMineProfileCell class])];
    [tableView registerClass:[JQMineSetLogoutCell class] forCellReuseIdentifier:NSStringFromClass([JQMineSetLogoutCell class])];
    
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    tableView.scrollEnabled = NO;
}

#pragma mark - InitNAV
///// 设置导航栏的背景图，默认为 NavBarBackgroundImage
- (nullable UIImage *)navigationBarBackgroundImage{
    //    return [UIImage new];
    return [UIImage svgImageNamed:@"mine_background" size:CGSizeMake(SCREEN_WIDTH, 215)];
#pragma mark - 设置 导航栏的背景图  效果
    //     return [UIImage imageNamed:@"home_background"]; //这里的timg就是那张叶子图
}

/// 设置当前导航栏的 barTintColor，默认为 NavBarBarTintColor
- (nullable UIColor *)navigationBarBarTintColor{
    return [UIColor clearColor];
#pragma mark - 设置 导航栏的背景 颜色
    //    return MYHome_backgroundColor;
}
// 系统状态栏
- (UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}
#pragma mark - deleagte
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 2;
}
- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    if (section == 0) {
        return 3;
    }
    return 1;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *headV = [[UIView alloc] init];
    headV.backgroundColor = tableView.backgroundColor;
    return headV;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *footV = [[UIView alloc] init];
    footV.backgroundColor = tableView.backgroundColor;
    return footV;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 48;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.000001;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 10;
}

- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
    
    if (indexPath.section == 0) {
        
        JQMineProfileCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([JQMineProfileCell class]) forIndexPath:indexPath];
        cell.backgroundColor = tableView.backgroundColor;
        [cell layoutIfNeeded];
        if ([tableView numberOfRowsInSection:indexPath.section]-1 == indexPath.row) {
//            [cell layoutIfNeeded];
            [cell.cellBackgroundV round:10 RectCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight];
        }
        if (indexPath.row == 0) {
//            [cell layoutIfNeeded];
            [cell.cellBackgroundV round:10 RectCorners:UIRectCornerTopLeft|UIRectCornerTopRight];
        }
        [cell setCellLb:self.nameArr[indexPath.row] cellDetailLb:nil];
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }else{
        JQMineSetLogoutCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([JQMineSetLogoutCell class]) forIndexPath:indexPath];
        cell.backgroundColor = tableView.backgroundColor;
        [cell layoutIfNeeded];
        [cell.cellBackgroundV round:10 RectCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight|UIRectCornerTopLeft|UIRectCornerTopRight];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        [cell setCellLbStr:@"退出登录"];
        return cell;
    }
    
    
    return [[UITableViewCell alloc] init];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0 && indexPath.section == 0) {
        JQMineSetSafeManageVC *setSafeVC = [[JQMineSetSafeManageVC alloc] init];
        [self.navigationController pushViewController:setSafeVC animated:YES];
        return;
    }
    if (indexPath.row == 2 && indexPath.section == 0){
        // 跳转 html 网页
        NSString *str = @"https://www.baidu.com";
        MYSimpleWebVC *vc = [[MYSimpleWebVC alloc] initWithURLString:str];
        [self.navigationController pushViewController:vc animated:YES];
    }
}

@end
